<template>
  <div>
    <van-button
      class="follow-btn"
      type="info"
      color="#3296fa"
      round
      size="small"
      icon="plus"
      v-if="!istFollowed"
      @click="onFll"
      :loading = "isFollLoading"
    >关注</van-button>
    <van-button
      class="follow-btn"
      round
      size="small"
      v-else
      @click="onFll"
      :loading = "isFollLoading"
    >已关注
    </van-button>
  </div>
</template>

<script>
import { follUser, deletUser } from '@/api/user.js'
export default {
  props: {
    istFollowed: {
      type: Boolean,
      require: true
    },
    autId: {
      // 对象 字符串 数字
      type: [Object, String, Number],
      require: true
    }
  },
  data () {
    return {
      isFollLoading: false
    }
  },

  created () {

  },
  // 修改 v-model
  model: {
    prop: 'istFollowed',
    event: 'updateFollowed'
  },
  methods: {
    // 关注
    async onFll () {
      this.isFollLoading = true
      try {
        if (this.istFollowed) {
          await deletUser(this.autId)
        } else {
          await follUser(this.autId)
        }
        this.$emit('updateFollowed', !this.istFollowed)
        this.isFollLoading = false
      } catch (err) {
        console.log('出差了')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
